package com.base;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.support.SqlSessionDaoSupport;

public class MybatisDao<T> extends SqlSessionDaoSupport{
	
	public SqlSession getSession(){
		return this.getSqlSession();
	};
	/**
	 * @desc 查询
	 * @param sqlId 
	 * @return List<T>
	 */
	public List<T> queryForList(String sqlId) {
		return getSession().selectList(sqlId);
	}
	/**
	 * @desc 查询
	 * @param sqlId
	 * @param param:where条件
	 * @return List<T>
	 */
	public List<T> queryForList(String sqlId,Object param) {
		return getSession().selectList(sqlId,param);
	}
	/**
	 * @desc 分页查询
	 * @param sqlId
	 * @param start:起始位置
	 * @param length:条数
	 * @return List<T>
	 */
	public List<T> queryForList(String sqlId,int start, int length){
		RowBounds rowBounds = new RowBounds(start,length);
		return this.getSession().selectList(sqlId,null,rowBounds);
	}
	/**
	 * @desc 分页查询
	 * @param sqlId
	 * @param param:where条件
	 * @param start:起始位置
	 * @param length:条数
	 * @return List<T>
	 */
	public List<T> queryForList(String sqlId,Object param,int start, int length){
		RowBounds rowBounds = new RowBounds(start,length);
		return this.getSession().selectList(sqlId,param,rowBounds);
	}
	/**
	 * @desc 分页查询(根据页码)
	 * @param sqlId
	 * @param pageNo:页码
	 * @param size:每页条数
	 * @return List<T>
	 */
	public List<T> queryForListByPageNo(String sqlId,int pageNo, int size){
		RowBounds rowBounds = new RowBounds((pageNo-1)*size,size);
		return this.getSession().selectList(sqlId,null,rowBounds);
	}
	/**
	 * @desc 分页查询(根据页码)
	 * @param sqlId
	 * @param param:where条件
	 * @param pageNo:页码
	 * @param size:每页条数
	 * @return List<T>
	 */
	public List<T> queryForListByPageNo(String sqlId,Object param,int pageNo, int size){
		RowBounds rowBounds = new RowBounds((pageNo-1)*size,size);
		return this.getSession().selectList(sqlId,param,rowBounds);
	}
	/**
	 * @param sqlId
	 */
	@SuppressWarnings("rawtypes")
	public Map queryForMap(String sqlId){
		return  this.getSession().selectMap(sqlId, null);
	}
	public int insertObj(String arg0,T arg1){
		return getSession().insert(arg0, arg1);
	}
}
